﻿<UserControl x:Class="Microsoft.Forums.ForumsClient.Views.ThreadedView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ForumsClient="clr-namespace:Microsoft.Forums.ForumsClient"
    xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
    xmlns:Views="clr-namespace:Microsoft.Forums.ForumsClient.Views"
    DataContext="{Binding Path=SelectedFolder.ThreadedViewModel}" >
    <UserControl.CommandBindings>
        <CommandBinding Command="{x:Static ForumsClient:Commands.ShowCreateReplyForm}"  CanExecute="ShowCreateReplyForm_CanExecute" Executed="ShowCreateReplyForm_Executed" />
        <CommandBinding Command="{x:Static ForumsClient:Commands.MarkAsAnswer}"  CanExecute="MarkAsAnswer_CanExecute" Executed="MarkAsAnswer_Executed" />
        <CommandBinding Command="{x:Static ForumsClient:Commands.MarkAsRead}"  CanExecute="MarkAsRead_CanExecute" Executed="MarkAsRead_Executed" />
    </UserControl.CommandBindings>
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary  Source="ColumnsTreeView.xaml" />
                <ResourceDictionary>
                    <CollectionViewSource Source="{Binding Path=Posts}" x:Key="viewSource">
                        <CollectionViewSource.SortDescriptions>
                            <scm:SortDescription PropertyName="Post.ThreadModifiedOn" Direction="Descending" />
                        </CollectionViewSource.SortDescriptions>
                    </CollectionViewSource>
                    <Views:UniversalToLocalTimeConverter x:Key="TimeConverter" />
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid  >
        <Grid.RowDefinitions>
            <RowDefinition  Height="50*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="50*" />
        </Grid.RowDefinitions>
    <Views:ColumnsTreeView  Grid.Row="0" x:Uid="threadedView" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  x:Name="threadedView"  
                         ItemsSource="{Binding Source={StaticResource viewSource}}" ItemTemplate="{StaticResource PostHierarchy}"    
                        SelectedItemChanged="ColumnsTreeView_SelectedItemChanged"
                        GridViewColumnHeader.Click ="ColumnHeader_Click" 
                        Keyboard.KeyDown="ThreadedView_KeyDown" >
            <Views:ColumnsTreeView.Columns>
                <GridViewColumn   x:Uid="GridViewColumn_1" Header="Subject" CellTemplate="{StaticResource FirstCell}" Width="100" />
                <GridViewColumn x:Uid="GridViewColumn_2" Header="Author" DisplayMemberBinding="{Binding Path=Post.CreatedBy.DisplayName}" Width="100" />
                <GridViewColumn x:Uid="GridViewColumn_4" Header="Modified Date" DisplayMemberBinding="{Binding Path=Post.ThreadModifiedOn, Converter={StaticResource TimeConverter}}" Width="100"  />
                <GridViewColumn x:Uid="GridViewColumn_3" Header="Created Date" DisplayMemberBinding="{Binding Path=Post.CreatedOn, Converter={StaticResource TimeConverter}}" Width="100"  />
            </Views:ColumnsTreeView.Columns>
        </Views:ColumnsTreeView>

        <GridSplitter Grid.Row="1"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Center"
                          ShowsPreview="True"
                          Background="Transparent"
                          Height="5"
                       />

        <Views:PostView Grid.Row="2" HtmlSource="{Binding Path=SelectedPostModel.Post.Body}" />
    </Grid>
</UserControl>
